package com.shengyuan.manage_os.old.ying.erpm;

import java.io.File;

import org.json.JSONObject;

import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.old.ying.erpm.controls.GpsButton;
import com.shengyuan.manage_os.old.ying.erpm.controls.PictureButton;
import com.shengyuan.manage_os.old.ying.erpm.controls.RecordButton;
import com.shengyuan.manage_os.old.ying.erpm.controls.SourceSelectMenu;
import com.shengyuan.manage_os.old.ying.erpm.controls.VideoButton;
import com.shengyuan.manage_os.old.ying.erpm.controls.SourceSelectMenu.OnPopClickListener;
import com.shengyuan.manage_os.old.ying.erpm.tasks.Submit_System_Setting_Data_Task;
import com.shengyuan.manage_os.old.ying.erpm.util.Utility;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;

public class Actual_Form_1 extends BaseActivity {

	private Spinner spinner_task;
	private EditText editText_car, editText_gongyingshang,editText_cailiao, editText_zhuangdi;
	private GpsButton GpsButton_Gps;
	private VideoButton VideoButton_Video;
	private RecordButton RecordButton_Record;
	private PictureButton PictureButton_Car, PictureButton_CaiLiao;

	@Override
	public void onClick(View view) {
		super.onClick(view);
		switch (view.getId()) {
		case R.id.editText_car:
			if (IsDoubleClick()) {
				Utility.HideEditFouce(editText_car);
				if (Submit_System_Setting_Data_Task.A_ZIYOUSHILUN!=null 
						&& Submit_System_Setting_Data_Task.A_ZIYOUSHILUN.length>0) {
					SourceSelectMenu menu = new SourceSelectMenu(editText_car);
					menu.setArrays(Submit_System_Setting_Data_Task.A_ZIYOUSHILUN);
					menu.show();
					menu.setOnPopClickListener(new onPopClickListener());
				}
			}
			break;
		case R.id.editText_gongyingshang:
			if (IsDoubleClick()) {
				Utility.HideEditFouce(editText_gongyingshang);
				if (Submit_System_Setting_Data_Task.A_GONYINGSHANG!=null 
						&& Submit_System_Setting_Data_Task.A_GONYINGSHANG.length>0) {
					SourceSelectMenu menu = new SourceSelectMenu(editText_gongyingshang);
					menu.setArrays(Submit_System_Setting_Data_Task.A_GONYINGSHANG);
					menu.show();
					menu.setOnPopClickListener(new onPopClickListener());
				}
			}
		case R.id.editText_cailiao:
			if (IsDoubleClick()) {
				Utility.HideEditFouce(editText_cailiao);
				if (Submit_System_Setting_Data_Task.A_CAILIAOMINGCHENG!=null 
						&& Submit_System_Setting_Data_Task.A_CAILIAOMINGCHENG.length>0) {
					SourceSelectMenu menu = new SourceSelectMenu(editText_cailiao);
					menu.setArrays(Submit_System_Setting_Data_Task.A_CAILIAOMINGCHENG);
					menu.show();
					menu.setOnPopClickListener(new onPopClickListener());
				}
			}		
		case R.id.editText_zhuangdi:
			if (IsDoubleClick()) {
				Utility.HideEditFouce(editText_zhuangdi);
				if (Submit_System_Setting_Data_Task.A_ZHUANGDI!=null 
						&& Submit_System_Setting_Data_Task.A_ZHUANGDI.length>0) {
					SourceSelectMenu menu = new SourceSelectMenu(editText_zhuangdi);
					menu.setArrays(Submit_System_Setting_Data_Task.A_ZHUANGDI);
					menu.show();
					menu.setOnPopClickListener(new onPopClickListener());
				}
			}				
		default:
			break;
		}
	}
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.actual_form_1);
		super.onCreate(savedInstanceState);
		InitControls();
	}

	@Override
	public void Save(Boolean IsJson1) {
//		Actual_Data_Table dbo = new Actual_Data_Table(this);
//		int maxid = dbo.Save_Data(MyID(), "", "", "user", 1, 0, 0);
//		dbo.Update_Data(maxid, dbo.JSON2, "value");
//		dbo.close();
		
		JSONObject json = new JSONObject();
		try {
			json.put( getString(R.string.actual_form), MyID());
			json.put( getString(R.string.title_actual_form_spinner_task), spinner_task.getSelectedItem().toString());
			json.put( getString(R.string.title_actual_form_editText_car), editText_car.getText().toString());
			json.put( getString(R.string.title_actual_form_editText_gongyingshang), editText_gongyingshang.getText().toString());
			json.put( getString(R.string.title_actual_form_editText_cailiao), editText_cailiao.getText().toString());
			json.put( getString(R.string.title_actual_form_editText_zhuangdi), editText_zhuangdi.getText().toString());
			json.put( getString(R.string.title_actual_form_GpsButton_Gps), GpsButton_Gps.mlocation+";"+GpsButton_Gps.x + ";" + GpsButton_Gps.y);

			json.put( getString(R.string.title_actual_form_VideoButton_Video), VideoButton_Video.VideoFileName);
			json.put( getString(R.string.title_actual_form_RecordButton_Record), RecordButton_Record.VoiceFileName);
			json.put( getString(R.string.title_actual_form_PictureButton), PictureButton_Car.PictureFileName);
			json.put( getString(R.string.title_actual_form_PictureButton), PictureButton_CaiLiao.PictureFileName);
			
			long time = System.currentTimeMillis();
			File dirFile = new File(time+"");
			if (!dirFile.exists()) {
				dirFile.mkdir();
			}
		} catch (Exception e) {
		}
	}

//	@Override
//	public void Back() {
//		super.Back();
//		
//	}

	@Override
	public void InitControls() {
		super.InitControls();
		spinner_task = (Spinner) findViewById(R.id.spinner_task);
		editText_car = (EditText) findViewById(R.id.editText_car);
		editText_gongyingshang = (EditText) findViewById(R.id.editText_gongyingshang);
		editText_cailiao = (EditText) findViewById(R.id.editText_cailiao);
		editText_zhuangdi = (EditText) findViewById(R.id.editText_zhuangdi);
		GpsButton_Gps = (GpsButton) findViewById(R.id.GpsButton_Gps);
		VideoButton_Video = (VideoButton) findViewById(R.id.VideoButton_Video);
		RecordButton_Record = (RecordButton) findViewById(R.id.RecordButton_Record);
		PictureButton_Car = (PictureButton) findViewById(R.id.PictureButton_Car);
		PictureButton_CaiLiao = (PictureButton) findViewById(R.id.PictureButton_CaiLiao);
		
		editText_car.setOnClickListener(this);
		editText_gongyingshang.setOnClickListener(this);
		editText_cailiao.setOnClickListener(this);
		editText_zhuangdi.setOnClickListener(this);
		
		if (Submit_System_Setting_Data_Task.A_GONGCHENGMINGCHENG_GC!=null) {
			ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
					R.layout.simple_spinner_item, 
					Submit_System_Setting_Data_Task.A_GONGCHENGMINGCHENG_GC);
			adapter.setDropDownViewResource(R.layout.simple_spinner_item_select);
			spinner_task.setAdapter(adapter);
		}else {
			Utility.MessageBox(this,"工程基础数据没有初始化");
			this.finish();
		}
	}

	public class onPopClickListener implements OnPopClickListener {
		@Override
		public void onPopClick(int index, String text, View anchor) {
			EditText etext = (EditText) anchor;
			if (etext!=null) {
				etext.setText(text);
			}
			
			
		}
	}

	@Override
	public Boolean IsPassed() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	protected void SaveJsonData() {
		// TODO Auto-generated method stub
		
	}
	@Override
	protected void SaveSelfPic(String sPath) {
		// TODO Auto-generated method stub
		
	}

}
